package 分治;

/**
 * @description:
 * @author: ywk
 * @date: 2020-07-19
 */
public class 两个数组的中位数 {
    public static void FindMedian(int[] A, int aL, int aR, int[] B, int bL, int bR) {
        int amid = aL + (aR - aL) / 2;
        int atemp = A[amid];

        int bmid = bL + (bR - bL) / 2;
        int btemp = B[bmid];

        if (aR - aL + bR - bL < 4) {
            System.out.println(atemp);
            System.out.println(btemp);

            return;
        } else if (atemp < btemp) {
            FindMedian(A, amid, aR, B, bL, bmid + 1);
        } else {
            FindMedian(A, aL, amid + 1, B, bmid + 1, bR);
        }
    }

    public static void main(String[] args) {
        int[] arr1 = {8, 9,11};
        int[] arr2 = {1,3, 4,8};
        FindMedian(arr1, 0, arr1.length - 1, arr2, 0, arr2.length - 1);
    }
}
